/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 * File Name     : roce_netlink.h
 * Version       : v2.0
 * Created       : 2023/8/29
 * Last Modified : 2023/8/29
 * Description   : The definition of RoCE CHar device related functions.
 */

#ifndef _ROCE_NETLINK_H_
#define _ROCE_NETLINK_H_
#ifdef ROCE_NETLINK_EN
#include <net/genetlink.h>
#include <net/netlink.h>
#include <net/net_namespace.h>
#include <linux/netlink.h>

#include "udk_usrnl.h"
#include "roce_k_ioctl.h"
#include "roce.h"

#define USRNL_GENL_ATTR_MAX (__USRNL_GENL_ATTR_MAX - 1)

/* netlink server info in roce ko */
#define ROCE3_FAMILY     "ROCE"
#define ROCE3_VERSION    0x1
#define ROCE_MAX_FUNCTION 128
#define PF_MAX_SIZE 32
#define VF_USE_SIZE 96

#define P2PCOS_MAX_VALUE 2
#define MAX_COS_NUM 0x7

enum hiroce_drv_cmd_type {
    HIROCE_DRV_CMD_DCB_GET = 100,
    HIROCE_DRV_CMD_CREATE_AH,
    HIROCE_DRV_CMD_MAX
};

typedef struct hiroce_dev_dcbinfo_get {
    usrnl_drv_msg_hdr_s hdr;
    union roce3_query_dcb_buf dcb_info;
    uint16_t func_id;
    uint16_t rsvd;
}hiroce_dev_dcbinfo_get_s;

typedef struct hiroce_dev_dcbinfo_rsp {
    usrnl_drv_msg_hdr_s hdr;
    union roce3_query_dcb_buf dcb_info;
}hiroce_dev_dcbinfo_rsp_s;

typedef struct hiroce_dev_ah_info {
    usrnl_drv_msg_hdr_s hdr;
    union roce3_create_ah_buf ah_info;
    uint16_t func_id;
    uint16_t rsvd;
}hiroce_dev_ah_info_s;

typedef struct netlink_dev {
    struct roce3_device *rdev[ROCE_MAX_FUNCTION];
}netlink_dev_s;

typedef struct hiroce_netlink_dev {
    int used_dev_num;
    netlink_dev_s *netlink;
    struct mutex mutex_dev;
}hiroce_netlink_dev_s;

int get_instance_of_func_id(int glb_func_id);
hiroce_netlink_dev_s *hiroce_get_adp(void);
int roce3_netlink_init(void);
void roce3_netlink_unit(void);

#endif // ROCE_NETLINK_EN
#endif
